<div style="font-size:12px;">
    With this example we demonstrate 3 new methods <br/>
    1. navButtonAdd - with help of this method we can add custom buttons in page bar. <br/>
    2. GridToForm - this method fill the form data from grid with a given row id and form id. <br/>
    3. FormToGrid - this method fill the Grid row with data from a given form id. <br/>
    Select a row. Then click a edit button. Try to change some values in form and then click Save button.<br/>
    Note: data is not saved to the server.
</div>
<br/>
<br/>
<table id="custbut" class="scroll"></table>
<div id="pcustbut" class="scroll" style="text-align:center;"></div>
<br/>
<form method="post" name="order" id="order" action="" title='' style="width:350px;margin:0px;">
	<fieldset>
		<legend>Invoice Data</legend>
		<table>
			<tbody>
				<tr>
					<td> Invice No:</td>
					<td><input type="text" name="id" readonly=true id="invid"/></td>
				</tr>
				<tr>
					<td> Invice Date:</td>
					<td><input type="text" name="invdate"  /></td>
				</tr>
				<tr>
					<td> Client</td>				
					<td><input type="text" name="name"  /></td>
				</tr>
				<tr>
					<td> Amount</td>				
					<td><input type="text" name="amount"  /></td>
				</tr>
				<tr>
					<td> Tax</td>				
					<td><input type="text" name="tax"  /></td>
				</tr>
				<tr>
					<td> Total</td>				
					<td><input type="text" name="total"  /></td>
				</tr>
				<tr>
					<td> Note</td>				
					<td><input type="text" name="note"  /></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td><input type="button" id="savedata" value="Save" /></td>
				</tr>
			</tbody>
		</table>
	</fieldset>
</form>

<script src="custbutt.js" type="text/javascript"> </script>
<br />
<br />
<div style="font-size:12px;">
<b> HTML </b>
<XMP>
...
<table id="custbut" class="scroll"></table>
<div id="pcustbut" class="scroll" style="text-align:center;"></div>
<br/>
<form method="post" name="order" id="order" action="" title='' style="width:350px;margin:0px;">
	<fieldset>
		<legend>Invoice Data</legend>
		<table>
			<tbody>
				<tr>
					<td> Invice No:</td>
					<td><input type="text" name="id" readonly=true id="invid"/></td>
				</tr>
				<tr>
					<td> Invice Date:</td>
					<td><input type="text" name="invdate"  /></td>
				</tr>
				<tr>
					<td> Client</td>				
					<td><input type="text" name="name"  /></td>
				</tr>
				<tr>
					<td> Amount</td>				
					<td><input type="text" name="amount"  /></td>
				</tr>
				<tr>
					<td> Tax</td>				
					<td><input type="text" name="tax"  /></td>
				</tr>
				<tr>
					<td> Total</td>				
					<td><input type="text" name="total"  /></td>
				</tr>
				<tr>
					<td> Note</td>				
					<td><input type="text" name="note"  /></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td><input type="button" id="savedata" value="Save" /></td>
				</tr>
			</tbody>
		</table>
	</fieldset>
</form>

<script src="custbutt.js" type="text/javascript"> </script>

</XMP>    
<b>Java Scrpt code</b>
<XMP>
...
jQuery("#custbut").jqGrid({        
   	url:'server.php?q=1',
	datatype: "xml",
   	colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
   	colModel:[
   		{name:'id',index:'id', width:55},
   		{name:'invdate',index:'invdate', width:90},
   		{name:'name',index:'name', width:100},
   		{name:'amount',index:'amount', width:80, align:"right"},
   		{name:'tax',index:'tax', width:80, align:"right"},		
   		{name:'total',index:'total', width:80,align:"right"},		
   		{name:'note',index:'note', width:150, sortable:false}		
   	],
   	rowNum:5,
   	rowList:[5,10,20],
   	imgpath: gridimgpath,
   	pager: jQuery('#pcustbut'),
   	sortname: 'id',
    viewrecords: true,
    sortorder: "desc",
    height: '100%',
    caption:"Custom Buttons and forms"
}).navGrid('#pcustbut',{edit:false,add:false,del:false})
.navButtonAdd('#pcustbut',{caption:"Edit",
	onClickButton:function(){
		var gsr = jQuery("#custbut").getGridParam('selrow');
		if(gsr){
			jQuery("#custbut").GridToForm(gsr,"#order");
		} else {
			alert("Please select Row")
		}							
} 
});
jQuery("#savedata").click(function(){
	var invid = jQuery("#invid").val();
	if(invid) {
		jQuery("#custbut").FormToGrid(invid,"#order");
	}
	
});
</XMP>
<b>PHP with MySQL</b>
<XMP>
...
$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
if(!$sidx) $sidx =1;
// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());

mysql_select_db($database) or die("Error conecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.client_id=b.client_id");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];

if( $count >0 ) {
	$total_pages = ceil($count/$limit);
} else {
	$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
$SQL = "SELECT a.id, a.invdate, b.name, a.amount,a.tax,a.total,a.note FROM invheader a, clients b WHERE a.client_id=b.client_id ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldnt execute query.".mysql_error());

if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
header("Content-type: application/xhtml+xml;charset=utf-8"); } else {
header("Content-type: text/xml;charset=utf-8");
}
$et = ">";

echo "<?xml version='1.0' encoding='utf-8'?$et\n";
echo "<rows>";
echo "<page>".$page."</page>";
echo "<total>".$total_pages."</total>";
echo "<records>".$count."</records>";
// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
	echo "<row id='". $row[id]."'>";			
	echo "<cell>". $row[id]."</cell>";
	echo "<cell>". $row[invdate]."</cell>";
	echo "<cell><![CDATA[". $row[name]."]]></cell>";
	echo "<cell>". $row[amount]."</cell>";
	echo "<cell>". $row[tax]."</cell>";
	echo "<cell>". $row[total]."</cell>";
	echo "<cell><![CDATA[". $row[note]."]]></cell>";
	echo "</row>";
}
echo "</rows>";		
...
</XMP>
</div>